package io.lckgroup.modules.lck.utils.order;

import com.alibaba.fastjson.JSONObject;

/**
 * 公共响应封装类
 */
public class Rsp {
    public static final String SUCCESS_CODE = "00000200";

    private String code = "00000200";
    private String msg = "成功";
    private Object data;


    public Rsp() {

    }

    public Rsp(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Rsp(String code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    /**
     * 判断是否成功
     *
     * @param rsp 返回信息
     * @return
     */
    public static boolean isSuccess(Rsp rsp) {
        if (SUCCESS_CODE.equals(rsp.getCode())) {
            return true;
        }
        return false;
    }

    public boolean successed() {
        return SUCCESS_CODE.equals(code);
    }

    @Override
    public String toString() {
        JSONObject rspJson = new JSONObject();
        rspJson.put("code", code);
        rspJson.put("msg", msg);
        rspJson.put("data", data);
        return rspJson.toJSONString();
    }

//	@Override
//	public String toString() {
//		return "{" +
//				"code='" + code + '\'' +
//				", msg='" + msg + '\'' +
//				", data=" + data +
//				'}';
//	}


}
